package com.chaowen.yixin;

import android.os.Bundle;
import android.os.Handler;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;

import com.chaowen.model.UserInfo;
import com.chaowen.service.TaskContext;

public class Fragment_sign extends Fragment_super {

	private Handler handler;
	public static Button signBtn;

	public Fragment_sign(Handler handler) {
		this.handler = handler;
	}

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		View view = inflater.inflate(R.layout.fragment_sign, container, false);
		initView(view);
		if (UserInfo.isSign) {
			signBtn.setEnabled(false);
			signBtn.setText("签到成功");
			signBtn.setBackgroundResource(R.drawable.press_button);
		} else {
			if (UserInfo.isLogin) {
				signBtn.setEnabled(true);
			}else {
				signBtn.setEnabled(false);
				signBtn.setText("请先登陆");
				signBtn.setBackgroundResource(R.drawable.press_button);
			}
		}
		return view;
	}

	private void initView(View view) {
		signBtn = (Button) view.findViewById(R.id.signBtn);
		signBtn.setOnClickListener(this);
	}

	@Override
	public void onClick(View view) {
		sign();
	}

	private void sign() {
		signBtn.setText("正在签到中...");
//		// 参数有：用户名、密码
//		new SignTask(this.handler).execute();
//		Task task = TaskFactory.createTask("sign");
//		task.setHandler(handler);
//		task.execute();
		new TaskContext("SignTask").doTask(handler);
	}

}
